/**
 * Created by Smartown(<a href='https://github.com/smartown'>@Smartown</a>) on 2017/6/3.
 *
 * 函数
 */
package win.smartown.kotlin.grammar

fun main(args: Array<String>) {
    println("Hello Kotlin.")
    testSum1()
    testSum2()
    testSum3(7, 8)
    testSum4(4, 8)
}

fun testSum1() {
    println("testSum1:")
    print("sum of 3 and 5 is ")
    println(sum1(3, 5))
}

//定义一个函数，接受两个int型参数，返回值为int
fun sum1(a: Int, b: Int): Int {
    return a + b
}

fun testSum2() {
    println("testSum2:")
    print("sum of 4 and 7 is ")
    println(sum2(4, 7))
}

//该函数只有一个表达式函数体以及一个子推导型的返回值
fun sum2(a: Int, b: Int) = a + b

//返回一个没有意义的值
fun testSum3(a: Int, b: Int): Unit {
    println("testSum3:")
    println("sum of $a and $b is ${a + b}")
}

//Unit的返回类型可以省略
fun testSum4(a: Int, b: Int) {
    println("testSum4:")
    println("sum of $a and $b is ${a + b}")
}